﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Experimental.Playables.CameraPlayable
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;
using UnityEngine.Playables;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine.Experimental.Playables
{
  /// <summary>
  ///   <para>An implementation of IPlayable that produces a Camera texture.</para>
  /// </summary>
  [StaticAccessor("CameraPlayableBindings", StaticAccessorType.DoubleColon)]
  [NativeHeader("Runtime/Export/Director/CameraPlayable.bindings.h")]
  [RequiredByNativeCode]
  [NativeHeader("Runtime/Director/Core/HPlayable.h")]
  [NativeHeader("Runtime/Camera//Director/CameraPlayable.h")]
  public struct CameraPlayable : IPlayable, IEquatable<CameraPlayable>
  {
    private PlayableHandle m_Handle;

    /// <summary>
    ///   <para>Creates a CameraPlayable in the PlayableGraph.</para>
    /// </summary>
    /// <param name="graph">The PlayableGraph object that will own the CameraPlayable.</param>
    /// <param name="camera">Camera used to produce a texture in the PlayableGraph.</param>
    /// <returns>
    ///   <para>A CameraPlayable linked to the PlayableGraph.</para>
    /// </returns>
    public static CameraPlayable Create(PlayableGraph graph, Camera camera)
    {
      return new CameraPlayable(CameraPlayable.CreateHandle(graph, camera));
    }

    private static PlayableHandle CreateHandle(PlayableGraph graph, Camera camera)
    {
      PlayableHandle handle = PlayableHandle.Null;
      return !CameraPlayable.InternalCreateCameraPlayable(ref graph, camera, ref handle) ? PlayableHandle.Null : handle;
    }

    internal CameraPlayable(PlayableHandle handle)
    {
      this.m_Handle = !handle.IsValid() || handle.IsPlayableOfType<CameraPlayable>() ? handle : throw new InvalidCastException("Can't set handle: the playable is not an CameraPlayable.");
    }

    public PlayableHandle GetHandle() => this.m_Handle;

    public static implicit operator Playable(CameraPlayable playable)
    {
      return new Playable(playable.GetHandle());
    }

    public static explicit operator CameraPlayable(Playable playable)
    {
      return new CameraPlayable(playable.GetHandle());
    }

    public bool Equals(CameraPlayable other) => this.GetHandle() == other.GetHandle();

    public Camera GetCamera() => CameraPlayable.GetCameraInternal(ref this.m_Handle);

    public void SetCamera(Camera value)
    {
      CameraPlayable.SetCameraInternal(ref this.m_Handle, value);
    }

    [NativeThrows]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern Camera GetCameraInternal(ref PlayableHandle hdl);

    [NativeThrows]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetCameraInternal(ref PlayableHandle hdl, Camera camera);

    [NativeThrows]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool InternalCreateCameraPlayable(
      ref PlayableGraph graph,
      Camera camera,
      ref PlayableHandle handle);

    [NativeThrows]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool ValidateType(ref PlayableHandle hdl);
  }
}
